<template>
  <div class="deviceStatus">
    <div class="device-title">
      <div class="title-name"><i class="el-icon-tickets"></i>预警信息</div>
      <div class="resetBnt">
        <!-- <el-tooltip
          class="item"
          effect="dark"
          content="故障检测"
          placement="top-start"
        >
          <i class="el-icon-full-screen" @click="checkDeviceStatus"></i>
        </el-tooltip> -->
        <el-tooltip
          class="item"
          effect="dark"
          content="刷新"
          placement="top-start"
        >
          <i class="el-icon-refresh" @click="getJobLog"></i>
        </el-tooltip>
        <el-tooltip
          class="item"
          effect="dark"
          content="查看详细日志"
          placement="top-start"
        >
          <i
            class="el-icon-position"
            @click="$router.push({ path: '/monitor/job-log/index' })"
          ></i>
        </el-tooltip>
      </div>
    </div>
    <div class="scroll-box" v-if="deviceList.length != 0" v-loading="loading">
      <vueSeamlessScroll
        :data="deviceList"
        class="warp"
        :class-option="classOption"
        
      >
        <ul class="item" v-show="!loading">
          <li v-for="(item, index) in deviceList" :key="index">
            <div class="box">
              <div class="content">
                <div class="bottomleft-title">
                  <div class="bottomleft-name">
                    <div class="sub-title">任务名:</div>
                    <span>{{ item.jobName }}</span>
                  </div>
                  <div class="date">
                    <span> {{ item.createTime }}</span>
                    <div class="sub-title">时间:</div>
                  </div>
                </div>
                <div class="address">
                  <div class="sub-title">信息:</div>
                  <el-tooltip
                    effect="dark"
                    :content="item.jobMessage"
                    placement="left"
                  >
                    <div class="message">{{ item.jobMessage }}</div>
                  </el-tooltip>
                </div>
              </div>
              <div class="end" style="color: red">
                <el-tag :type="item.status * 1 == 0 ? 'primary' : 'danger'">
                  {{ item.status | textStatus }}
                </el-tag>
              </div>
            </div>
          </li>
        </ul>
      </vueSeamlessScroll>
    </div>
     <div class="emptyText" v-else>设备状态正常，暂无报警日志</div>
  </div>
</template>

<script>
import vueSeamlessScroll from "vue-seamless-scroll";
import { listJobLog } from "@/api/monitor/jobLog.js";
export default {
  components: {
    vueSeamlessScroll,
  },
  data() {
    return {
      deviceList: [],
      radio: 3,
      classOption: {
        direction: 1,
        singleHeight: 63,
        waitTime: 10000,
        step: 2,
      },
      loading: false,
      isCollspae: false,
      timer: null,
    };
  },
  methods: {
    resetData() {
      this.loading = true;
      setTimeout(() => {
        this.loading = false;
      }, 2000);
    },
    checkDeviceStatus() {
      this.$emit("loadingDevice");
    },
    getJobLog() {
      // this.loading = true;
      let params = {
        pageNum: 1,
        pageSize: 20,
        status: 1,
      };
      listJobLog(params).then((res) => {
        this.deviceList = res.rows;
        this.loading = false;
      });
    },
  },

  created() {
    this.getJobLog();
    this.timer = setInterval(() => {
      this.getJobLog();
    }, 30000);
  },
  beforeDestroy() {
    clearInterval(this.timer);
  },
  filters: {
    textStatus(arg) {
      let arr = ["成功", "失败", "警告"];
      return arr[arg * 1];
    },
  },
};
</script>

<style lang="less" scoped>
.deviceStatus {
  position: absolute;
  left: 10px;
  top: 10px;
  width: 650px;
  height: 165px;
  display: flex;
  flex-direction: column;
  border: 1px dashed #0077d1;
  border-radius: 10px;
  overflow: hidden;
  .device-title {
    font-size: 20px;
    font-weight: bold;
    display: flex;
    align-items: center;
    min-height: 35px;
    background-color: #fff;
    z-index: 999;
    box-shadow: 3px 3px 3px #e9ebec;
    .title-name {
      margin-left: 10px;
      letter-spacing: 1.5px;
      margin-left: 5px;
    }
    .resetBnt {
      margin-left: auto;
      font-size: 26px;
      margin-right: 10px;
      cursor: pointer;
      i {
        margin-left: 5px;
      }
      i:hover {
        color: #00afed;
      }
    }
  }
  .list {
    display: flex;
    flex-wrap: wrap;
    overflow: auto;
    .device-title {
      font-size: 20px;
      font-weight: bold;
    }
    .device-item {
      width: 120px;
      height: 30px;
      display: flex;
      align-items: center;
      font-size: 18px;
      font-weight: bold;
      overflow: hidden;
      white-space: nowrap;
      text-overflow: ellipsis;
    }
    .device-status {
      width: 20px;
      height: 20px;
      border-radius: 50%;
      background-color: #0dbc79;
      margin-left: auto;
      margin-right: 10px;
    }
  }
  .emptyText {
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
  }
  .warp {
    width: 650px;
    height: 164px;
    margin: 0 auto;

    ul {
      list-style: none;
      padding: 0;
      margin: 0 auto;

      li,
      a {
        display: block;
        height: 63px;
        // line-height: 30px;
        display: flex;
        justify-content: space-between;
        font-size: 15px;
        border-bottom: 2px dashed #00afed;

        .box {
          width: 100%;
          height: 100%;
          display: flex;
          flex-wrap: wrap;
          .sub-title {
            font-weight: bold;
          }
          .content {
            padding-top: 0px;
            flex: 1;
            height: 100%;
            display: flex;
            justify-content: space-around;
            flex-direction: column;

            .bottomleft-title {
              display: flex;
              font-size: 14px;

              .bottomleft-name {
                width: 50%;
                height: 100%;
                font-size: 17px;
                display: flex;
                margin-left: 10px;
                letter-spacing: 2px;
                span {
                  min-width: 100px;
                  font-size: 16px;
                  color: #147cdc;
                  font-weight: bold;
                  letter-spacing: 2px;
                }
              }

              .date {
                flex: 1;
                display: flex;
                flex-direction: row-reverse;
                font-size: 17px;
                display: flex;
                span {
                  font-size: 17px;
                  display: flex;
                  align-items: center;
                  transform: translateY(2px);
                  margin-left: 10px;
                }
              }
            }
            .address {
              width: 100%;
              font-size: 17px;
              margin-left: 10px;
              display: flex;
              .message {
                max-width: 470px;
                font-size: 14px;
                overflow: hidden;
                white-space: nowrap;
                text-overflow: ellipsis;
                transform: translateY(2px);
              }
            }
          }

          .end {
            width: 20%;
            height: 100%;
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 17px;
            font-weight: bold;
            letter-spacing: 2px;
          }
        }
      }
    }
  }
}
</style>>
